package algotithm.jianzhioffer.test16;

/**
 * @author zhouyanxiang
 * @Date 2020-12-2020/12/16-14:54
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        double pow = solution.myPow(2.1, 3);
        System.out.println(pow);
    }

    public double myPow(double x, int n) {
        double res = 1.0;
        if (x == 0) {
            return 0;
        }
        long b = n;
        if (n < 0) {
            x = 1 / x;
            b = -b;
        }
        while (b > 0) {
            if ((b & 1) == 1) {
                res *= x;
            }
//            res *= x*x;
            x *= x;
            b >>= 1;
        }
        return res;
    }
}
